package com.srmt.common.ratelimit.config;

/**
 * API端点定义
 * 定义飞书SDK中所有需要限流的API端点
 * 
 * @author SRMT Development Team
 * @since 1.0.0
 */
public enum ApiEndpoint {
    
    // Document APIs
    DOCX_DOCUMENT_CREATE("docxDocumentCreate", "创建文档", 10),
    DOCX_DOCUMENT_GET("docxDocumentGet", "获取文档", 50),
    DOCX_DOCUMENT_PATCH("docxDocumentPatch", "更新文档", 20),
    DOCX_DOCUMENT_RAW_CONTENT("docxDocumentRawContent", "获取文档原始内容", 30),
    
    // Document Block APIs
    DOCX_DOCUMENT_BLOCK_LIST("docxDocumentBlockList", "列出文档块", 30),
    DOCX_DOCUMENT_BLOCK_GET("docxDocumentBlockGet", "获取文档块", 50),
    DOCX_DOCUMENT_BLOCK_PATCH("docxDocumentBlockPatch", "更新文档块", 20),
    DOCX_DOCUMENT_BLOCK_BATCH_UPDATE("docxDocumentBlockBatchUpdate", "批量更新文档块", 10),
    
    // Document Block Children APIs
    DOCX_DOCUMENT_BLOCK_CHILDREN_CREATE("docxDocumentBlockChildrenCreate", "创建子文档块", 20),
    DOCX_DOCUMENT_BLOCK_CHILDREN_LIST("docxDocumentBlockChildrenList", "列出子文档块", 30),
    
    // Document Block Descendant APIs
    DOCX_DOCUMENT_BLOCK_DESCENDANT_CREATE("docxDocumentBlockDescendantCreate", "创建后代文档块", 20),
    
    // Drive APIs
    DRIVE_FILE_COPY("driveFileCopy", "复制文件", 10),
    DRIVE_FILE_DELETE("driveFileDelete", "删除文件", 10),
    DRIVE_FILE_GET("driveFileGet", "获取文件", 50),
    DRIVE_FILE_LIST("driveFileList", "列出文件", 30),
    
    // Permission APIs
    DRIVE_PERMISSION_MEMBER_CREATE("drivePermissionMemberCreate", "创建权限成员", 20),
    DRIVE_PERMISSION_MEMBER_UPDATE("drivePermissionMemberUpdate", "更新权限成员", 20),
    DRIVE_PERMISSION_MEMBER_DELETE("drivePermissionMemberDelete", "删除权限成员", 20),
    DRIVE_PERMISSION_MEMBER_LIST("drivePermissionMemberList", "列出权限成员", 30),
    
    // Contact APIs
    CONTACT_USER_BATCH_GET_ID("contactUserBatchGetId", "批量获取用户ID", 30),
    CONTACT_USER_GET("contactUserGet", "获取用户信息", 50),
    CONTACT_USER_LIST("contactUserList", "列出用户", 30),

    // Sheets APIs - Basic Operations
    SHEETS_SPREADSHEET_GET("sheetsSpreadsheetGet", "获取电子表格信息", 50),
    SHEETS_SPREADSHEET_CREATE("sheetsSpreadsheetCreate", "创建电子表格", 10),
    SHEETS_SPREADSHEET_SHEET_GET("sheetsSpreadsheetSheetGet", "获取工作表信息", 50),
    SHEETS_SPREADSHEET_SHEET_QUERY("sheetsSpreadsheetSheetQuery", "查询工作表列表", 30),

    // Sheets APIs - Data Operations (v2)
    SHEETS_VALUES_GET("sheetsValuesGet", "读取单元格数据", 30),
    SHEETS_VALUES_UPDATE("sheetsValuesUpdate", "更新单元格数据", 20),
    SHEETS_VALUES_BATCH_UPDATE("sheetsValuesBatchUpdate", "批量更新单元格数据", 10),
    SHEETS_VALUES_PREPEND("sheetsValuesPrepend", "在上方插入数据", 20),
    SHEETS_VALUES_APPEND("sheetsValuesAppend", "追加数据", 20),

    // Sheets APIs - Dimension Operations (v2)
    SHEETS_DIMENSION_RANGE_ADD("sheetsDimensionRangeAdd", "增加空白行列", 20),
    SHEETS_DIMENSION_RANGE_INSERT("sheetsDimensionRangeInsert", "插入空白行列", 20),
    SHEETS_DIMENSION_RANGE_DELETE("sheetsDimensionRangeDelete", "删除行列", 20),
    SHEETS_DIMENSION_RANGE_UPDATE("sheetsDimensionRangeUpdate", "更新行高列宽", 20),

    // Sheets APIs - Cell Operations (v2)
    SHEETS_MERGE_CELLS("sheetsMergeCells", "合并单元格", 20),
    SHEETS_UNMERGE_CELLS("sheetsUnmergeCells", "取消合并单元格", 20),
    SHEETS_CELL_STYLE_SET("sheetsCellStyleSet", "设置单元格样式", 20),
    SHEETS_DATA_VALIDATION_SET("sheetsDataValidationSet", "设置数据验证", 20),

    // Sheets APIs - Protection Operations (v2)
    SHEETS_PROTECTED_DIMENSION_ADD("sheetsProtectedDimensionAdd", "添加保护范围", 10);
    
    private final String code;
    private final String description;
    private final int defaultQps;
    
    ApiEndpoint(String code, String description, int defaultQps) {
        this.code = code;
        this.description = description;
        this.defaultQps = defaultQps;
    }
    
    /**
     * 获取API端点代码
     */
    public String getCode() {
        return code;
    }
    
    /**
     * 获取API端点描述
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * 获取默认QPS限制
     */
    public int getDefaultQps() {
        return defaultQps;
    }
    
    /**
     * 根据代码查找API端点
     */
    public static ApiEndpoint fromCode(String code) {
        for (ApiEndpoint endpoint : values()) {
            if (endpoint.code.equals(code)) {
                return endpoint;
            }
        }
        return null;
    }
    
    /**
     * 从方法调用链中提取API端点
     * 例如: client.docx().v1().document().create() -> docx.document.create
     */
    public static String extractApiEndpoint(String methodChain) {
        if (methodChain == null || methodChain.isEmpty()) {
            return null;
        }
        
        // 移除client前缀和版本信息
        methodChain = methodChain.replace("client.", "")
                                 .replace(".v1()", "")
                                 .replace("()", "");
        
        // 转换为标准格式
        return methodChain.replace(".", ".")
                         .toLowerCase();
    }
}